<template>
	<view class="bg-white main">
		<view class="content_xh">
			<view class="content_top">
				<view class="content_top_images">
					<image :src="goods.image_url" mode="widthFix"></image>
				</view>
				<view class="content_top_main">
					<view class="content_top_main_one">{{goods.title}}</view>
					<view class="content_top_main_three">
						<!-- <view class="content_top_main_goldWeight">金重：{{goods.goldWeight}}</view> -->
						<view class="content_top_main_inventory">库存：{{goods.stock}}</view>
					</view>
					<view class="content_top_main_four hong">秒杀价：￥{{goods.price}}</view>
					<!-- <view class="content_top_main_four">
						<view class="content_top_main_jcPrice">
							<view class="">基础工费：</view>
							<view class="hong">{{goods.wholesaleWage}}元/g</view>
						</view>
						<view class="content_top_main_surcharge">
							<view class="">附加费：</view>
							<view class="hong">{{goods.wholesaleSurcharge}}元/g</view>
						</view>
					</view> -->
				</view>
			</view>
			<!-- 提示 -->
			<view class="order_tip">
				<view class="tip">提示：</view>
				<view class="tip_con">此价格为参考价，实际出货价格以线下结算为准!</view>
			</view>
			<!-- 商品列表 -->
			<view class="content_bottom">
				<view :class="'content_bottom_item '+ item.is_active" @tap="goods_spec_list_event"
					v-for="(item,index) in goods_spec_List" :key="index" :data-key="index">
					<view class="info">
						<!-- <view class="content_bottom_item_one">
							{{goods.goldColour}}（条码：{{item.barCode}}）{{goods.storeCategoryName}}
						</view> -->
						<view class="content_bottom_item_two">
							<view class="">金重：{{item.goldWeight}},</view>
							<!-- <view class="kc">库存：{{item.inventory}},</view> -->
							<!-- <view class="content_bottom_item_two_price">附加费：{{item.wholesaleSurcharge}}元/g</view> -->
						</view>
						<view class="red content_bottom_item_three">
							秒杀价格: ￥{{goods.price}}
						</view>
						<view class="content_bottom_item_four">
							<view class="">金料额：{{GoldMaterial(item)}},</view>
							<!-- 批发工费总额 -->
							<view class="content_bottom_item_four_price" v-if="vipCertification==='1'">
								工费总额：{{calculateTotalCost(item)}}元/g,
							</view>
							<!-- 销售工费总额 -->
							<view class="content_bottom_item_four_price">
								工费总额：{{calculateTotal(item)}}元/g,
							</view>
						</view>
					</view>
					<!-- 数量 -->
					<view class="many">
						<text class="many_item" @click.stop="jiannum(index)">-</text>
						<text class="many_item many_zero">{{buy_number[index]}}</text>
						<text class="many_item" @click.stop="addnum(index)">+</text>
					</view>
					<image v-show="(item.is_active || null) !=null" class="xuanzong"
						src="https://t1.chowtaiking.com.cn/img/ruoyi/2025/03/10/6e13315dca0b4ca5aa9d9c26caa25531.png">
					</image>
				</view>
			</view>
			<!-- 加入购物车 -->
			<view class="content_addCart addCart_xh">
				<view class="addCart" :data-type="'plugins-batchbuy-button-cart'" @tap="buy_submit_event">
					提交订单
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	const app = getApp();
	export default {
		props: ["goods", "goods_spec_List", "goods_list"],
		data() {
			return {
				vipCertification: 1,
				// token:"",
				params: {},
				back_data: {},
				popup_status: false,
				goods_spec_base_price: 0,
				goods_spec_base_original_price: 0,
				goods_spec_base_inventory: 0,
				goods_spec_base_buy_min_number: 0,
				goods_spec_base_buy_max_number: 0,
				goods_spec_base_images: '',
				goods_spec_base_id: 0,
				goods_spec_choose: [],
				buy_number: [],
				buy_event_type: 'cart',
				is_direct_cart: 0,
				is_success_tips: 1,
				state: [],
				goodsList: [],
				price: 0,
				xhstate: true,
				dhstate: false,
				stateSize: [],
				sizeList: ["54#", "56#", "58#", "60#"],
				num: 0,
				dhnum: 0,
				ggstyle: {
					color: "white",
					backgroundColor: "red",
					border: 0
				},
				ggList: [52, 53, 54, 55, 56, 57, 58, 59, 60],
				ggState: [],
				jzList: ["约30g", "约35g", "约40g", "约45g", "约50g", "约55g"],
				jzState: [],
				ssAdd: false,
				goodsInfo: {
					specify: "",
					goldWeight: "",
					number: ""
				},
				goodsLists: [],
				batchbuy_data: null,
				buy_button: null,
				back_data: null,
				nav_active_index: 0,

			};
		},

		components: {

		},
		methods: {
			// 初始化
			init(goods = {}, params = {}, back_data = null, batchbuy_data = null, buy_button = null, nav_active_index =
				0) {

				params = params || {};

				// 状态默认开启弹窗
				var status = true;
				// 商品可选规格
				var goods_spec_choose = ((goods.specifications || null) != null) ? (goods.specifications.choose || []) :
			[];
				var goods_spec_List = ((goods.spavList || null) != null) ? (goods.spavList || []) : [];
				// 无规格是否直接操作
				var is_direct_cart = 0;
				if ((params.is_direct_cart || 0) == 1 && parseInt(goods.is_exist_many_spec || 0) == 0 && goods_spec_choose
					.length == 0) {
					status = false;
					is_direct_cart = 1;
				}
				// 是否成功提示、默认提示
				var is_success_tips = (params.is_success_tips == undefined) ? 1 : params.is_success_tips || 0;
				// 直接加购、并且用户已经存在购物车则依次+1
				if (this.is_direct_cart == 1 && parseInt(this.goods.user_cart_count || 0) > 0) {
					var buy_number = 1;
				} else {
					var buy_number = goods.buy_min_number || 1;
				}
				// 设置数据
				this.popup_status = status
				this.params = params || {}
				this.back_data = back_data
				this.goods = goods || {}
				this.goods_spec_choose = goods_spec_choose
				this.goods_spec_List = goods_spec_List
				this.goods_spec_base_price = goods.price
				this.goods_spec_base_original_price = goods.original_price || 0
				this.goods_spec_base_inventory = goods.stock
				this.goods_spec_base_images = goods.images
				// this.buy_number = buy_number
				this.buy_event_type = params.buy_event_type || 'cart'
				this.is_direct_cart = is_direct_cart
				this.is_success_tips = is_success_tips
				this.price = 0

				// 不能选择规格处理
				this.spec_handle_dont(0, 1);

				// 是否默认选中第一个规格
				this.plugins_intellectstools_selected_spec_handle();

				// 是否直接操作加入购物车
				// if (is_direct_cart) {
				// 	this.spec_confirm_event();
				// }

			},
			// 默认选中第一个规格
			plugins_intellectstools_selected_spec_handle() {
				// 是否已选择
				var temp_data = this.goods_spec_choose;
				if (temp_data.length > 0) {
					var active_count = 0;
					for (var i in temp_data) {
						for (var k in temp_data[i]['value']) {
							if ((temp_data[i]['value'][k]['is_active'] || null) != null) {
								active_count++;
							}
						}
					}
					if (active_count > 0) {
						return false;
					}

					// 选择处理
					var self = this;
					// 销毁之前的任务
					clearInterval(self.plugins_intellectstools_timer);
					clearInterval(self.plugins_intellectstools_timerout);
					// 读取智能工具插件配置、是否开启
					var config = self.plugins_intellectstools_config || null;
					if (config != null && (config.is_goods_detail_selected_first_spec || 0) == 1) {
						// 必须存在购买和加入购物车任意一个、规格必须多个
						var buy = self.buy_button;
						var sku_count = app.globalData.get_length(temp_data);
						// 先清除价格展示信息
						self.setData({
							goods_spec_base_price: '...',
							goods_spec_base_original_price: '...'
						});
						var num = 0;
						var timer = setInterval(function() {
							for (var i in temp_data) {
								// 清除价格展示信息、避免获取价格类型赋值
								self.setData({
									goods_spec_base_price: '...',
									goods_spec_base_original_price: '...'
								});
								// 必须不存在已选择项
								var active = temp_data[i]['value'].map(function(v) {
									return v.is_active
								}).join('') || null;
								if (active == null) {
									var status = false;
									for (var k in temp_data[i]['value']) {
										// 必须是可选和未选
										if (!status && (temp_data[i]['value'][k]['is_disabled'] || null) == null &&
											(temp_data[i]['value'][k]['is_dont'] || null) == null) {
											self.goods_spec_choice_handle(i, k);
											status = true;
											num++;
										}
									}
								}
							}
							if (num >= sku_count) {
								clearInterval(self.plugins_intellectstools_timer);
							}
						}, 100);
						var timerout = setTimeout(function() {
							clearInterval(self.plugins_intellectstools_timerout);
						}, 20000);
						self.setData({
							plugins_intellectstools_timer: timer,
							plugins_intellectstools_timerout: timerout
						});
					}
				}
			},
			// 规格事件
			goods_spec_choice_event(e) {
				var key = e.currentTarget.dataset.key || 0;
				var keys = e.currentTarget.dataset.keys || 0;
				this.goods_spec_choice_handle(key, keys);
			},
			// 规格事件
			goods_spec_list_event(e) {
				var key = e.currentTarget.dataset.key || 0;
				this.goods_spec_list_handle(key);
			},
			// 规格选择处理
			goods_spec_list_handle(key) {
				var temp_spec = this.goods_spec_List;
				// 规格选择
				for (var i in temp_spec) {
					if (key == i) {
						var single_inventory = temp_spec[i]['inventory'];
						// 如果单个商品库存为0，则不能选择状态
						if (single_inventory === 0) {
							uni.showToast({
								title: "此规格没有库存了哦！",
								icon: "none"
							})
							return;
						}

						if ((temp_spec[i]['is_active'] || null) == null) {
							temp_spec[i]['is_active'] = 'xz';
							this.price = parseFloat(parseFloat(this.price) + parseFloat(temp_spec[i]['tradePrice']))
								.toFixed(2)
						} else {
							temp_spec[i]['is_active'] = '';
							this.price = parseFloat(parseFloat(this.price) - parseFloat(temp_spec[i]['tradePrice']))
								.toFixed(2)
						}
					}
				}
				this.goods_spec_List = temp_spec
			},
			// 规格选择处理
			goods_spec_choice_handle(key, keys) {
				var temp_spec = this.goods_spec_choose;
				// 不能选择和禁止选择跳过
				if ((temp_spec[key]['value'][keys]['is_dont'] || null) == null && (temp_spec[key]['value'][keys][
						'is_disabled'
					] || null) == null) {
					// 规格选择
					for (var i in temp_spec) {
						for (var k in temp_spec[i]['value']) {
							if ((temp_spec[i]['value'][k]['is_dont'] || null) == null && (temp_spec[i]['value'][k][
									'is_disabled'
								] || null) == null) {
								if (key == i) {
									if (keys == k && (temp_spec[i]['value'][k]['is_active'] || null) == null) {
										temp_spec[i]['value'][k]['is_active'] = 'cr-white bg-main br-main';
									} else {
										temp_spec[i]['value'][k]['is_active'] = '';
									}
								}
							}
						}
					}
					this.spec = temp_spec

					// 不能选择规格处理
					this.spec_handle_dont(key);

					// 获取下一个规格类型
					this.get_spec_type(key);

					// 获取规格详情
					this.get_spec_detail();
				}
			},
			// 获取下一个规格类型
			get_spec_type(key) {
				var temp_spec = this.goods_spec_choose;
				var active_index = parseInt(key) + 1;
				var sku_count = app.globalData.get_length(temp_spec);
				if (active_index <= 0 || active_index >= sku_count) {
					return false;
				}

				// 获取规格值
				var spec = [];
				for (var i in temp_spec) {
					for (var k in temp_spec[i]['value']) {
						if ((temp_spec[i]['value'][k]['is_active'] || null) != null) {
							spec.push({
								type: temp_spec[i]['name'],
								value: temp_spec[i]['value'][k]['name']
							});
							break;
						}
					}
				}
				if (spec.length <= 0) {
					return false;
				}

				// 获取数据
				var data = this.params;
				data['id'] = this.goods.id;
				data['spec'] = JSON.stringify(spec);
				let url = app.globalData.get_request_url("spectype");
				uni.request({
					url: url,
					data: data,
					method: 'POST',
					success: (res) => {
						if (res.data.code == 200) {
							var spec_type = res.data.data.spec_type;
							var spec_count = spec.length;
							var index = spec_count > 0 ? spec_count : 0;
							if (index < sku_count) {
								for (var i in temp_spec) {
									for (var k in temp_spec[i]['value']) {
										if (index == i) {
											temp_spec[i]['value'][k]['is_dont'] = '';
											var temp_value = temp_spec[i]['value'][k]['name'];
											var temp_status = false;
											for (var t in spec_type) {
												if (spec_type[t] == temp_value) {
													temp_status = true;
													break;
												}
											}
											if (temp_status == true) {
												temp_spec[i]['value'][k]['is_disabled'] = '';
											} else {
												temp_spec[i]['value'][k]['is_disabled'] =
													'spec-items-disabled';
											}
										}
									}
								}
								this.spec = temp_spec
							}
						} else {
							if (app.globalData.is_login_check(res.data, this, 'get_data')) {
								uni.showToast({
									icon: 'none',
									title: res.data.msg,
									duration: 3000
								});
							}
						}
						uni.hideLoading()
					}
				})
			},
			// 获取规格详情
			get_spec_detail() {
				// 获取规格值
				var spec = this.goods_selected_spec();
				// 存在规格的时候是否已完全选择规格
				var sku_count = this.goods_spec_choose.length;
				var active_count = spec.length;
				if (spec.length <= 0 || active_count < sku_count) {
					var buy_number = parseInt(this.buy_number);
					var buy_min_number = parseInt(this.goods.buy_min_number || 1);
					var buy_max_number = parseInt(this.goods.buy_max_number || 0);
					if (buy_number < buy_min_number) {
						buy_number = buy_min_number;
					}
					if (buy_max_number > 0 && buy_number > buy_max_number) {
						buy_number = buy_max_number;
					}
					this.goods_spec_base_price = this.goods.price
					this.goods_spec_base_original_price = this.goods.original_price || 0
					this.goods_spec_base_inventory = this.goods.inventory
					this.goods_spec_base_buy_min_number = 0
					this.goods_spec_base_buy_max_number = 0
					this.buy_number = buy_number
					return false;
				}

				// 获取数据
				var data = this.params;
				data['id'] = this.goods.id;
				data['spec'] = JSON.stringify(spec);
				data['stock'] = this.buy_number;

				let url = app.globalData.get_request_url("specdetail");
				uni.request({
					url: url,
					data: data,
					method: 'POST',
					success: (res) => {
						if (res.data.code == 200) {
							this.goods_spec_detail_back_handle(res.data.data);
						} else {
							if (app.globalData.is_login_check(res.data, this, 'get_data')) {
								uni.showToast({
									icon: 'none',
									title: res.data.msg,
									duration: 3000
								});
							}
						}
						uni.hideLoading()
					}
				})
			},

			// 商品规格详情返回数据处理
			goods_spec_detail_back_handle(data) {
				var spec_base = data.spec_base;
				var buy_number = parseInt(this.buy_number);
				var spec_buy_min_number = parseInt(spec_base.buy_min_number || 1);
				var spec_buy_max_number = parseInt(spec_base.buy_max_number || 0);
				if (spec_buy_min_number > 0 && buy_number < spec_buy_min_number) {
					buy_number = spec_buy_min_number;
				}
				if (spec_buy_max_number > 0 && buy_number > spec_buy_max_number) {
					buy_number = spec_buy_max_number;
				}
				this.goods_spec_base_price = spec_base.price
				this.goods_spec_base_original_price = spec_base.original_price || 0
				this.goods_spec_base_inventory = parseInt(spec_base.inventory || 0)
				this.goods_spec_base_buy_min_number = spec_buy_min_number
				this.goods_spec_base_buy_max_number = spec_buy_max_number
				this.buy_number = buy_number
				this.goods_spec_base_id = spec_base.id
			},
			// 已选的商品规格
			goods_selected_spec() {
				var spec = [];
				var temp_spec = this.goods_spec_choose;
				for (var i in temp_spec) {
					for (var k in temp_spec[i]['value']) {
						if ((temp_spec[i]['value'][k]['is_active'] || null) != null) {
							spec.push({
								type: temp_spec[i]['name'],
								value: temp_spec[i]['value'][k]['name']
							});
							break;
						}
					}
				}
				return spec;
			},
			// 不能选择规格处理
			spec_handle_dont(key, is_init = 0) {
				var temp_spec = this.goods_spec_choose || [];
				if (temp_spec.length <= 0) {
					return false;
				}

				// 是否不能选择
				key = parseInt(key);
				for (var i in temp_spec) {
					for (var k in temp_spec[i]['value']) {
						if (i > key) {
							temp_spec[i]['value'][k]['is_dont'] = 'spec-dont-choose';
							temp_spec[i]['value'][k]['is_disabled'] = '';
							temp_spec[i]['value'][k]['is_active'] = '';
						} else {
							if (is_init == 1) {
								temp_spec[i]['value'][k]['is_active'] = '';
							}
						}

						// 当只有一个规格的时候
						if (key == 0 && temp_spec.length == 1) {
							temp_spec[i]['value'][k]['is_disabled'] = (temp_spec[i]['value'][k]['is_only_level_one'] ||
									null) != null && parseInt(temp_spec[i]['value'][k]['inventory'] || 0) <= 0 ?
								'spec-items-disabled' : '';
						}
					}
				}
				this.spec = temp_spec
			},
			// 数量输入事件
			goods_buy_number_blur(e) {
				var number = parseInt(e.detail.value) || 1;
				if (isNaN(number)) {
					number = this.goods.buy_min_number || 1;
				}
				this.goods_buy_number_func(number);
			},

			// 数量操作事件
			goods_buy_number_event(e) {
				var type = parseInt(e.currentTarget.dataset.type || 0);
				var temp_number = parseInt(this.buy_number);
				var number = (type == 0) ? temp_number - 1 : temp_number + 1;
				this.goods_buy_number_func(number);
			},
			// 数量处理方法
			goods_buy_number_func(number) {
				var buy_min_number = parseInt(this.goods.buy_min_number || 1);
				var buy_max_number = parseInt(this.goods.buy_max_number || 0);
				var spec_buy_min_number = parseInt(this.goods_spec_base_buy_min_number || 0);
				var spec_buy_max_number = parseInt(this.goods_spec_base_buy_max_number || 0);
				var inventory = parseInt(this.goods_spec_base_inventory || 0);
				var inventory_unit = this.goods.inventory_unit;

				// 最小起购数量
				var min = (spec_buy_min_number > 0) ? spec_buy_min_number : buy_min_number;
				if (min > 0 && number < min) {
					number = min;
					uni.showToast({
						title: "起购" + min + inventory_unit
					})
				}

				// 最大购买数量
				var max = (spec_buy_max_number > 0) ? spec_buy_max_number : buy_max_number;
				if (max > 0 && number > max) {
					number = max;
					uni.showToast({
						title: "限购" + max + inventory_unit
					})
				}

				// 是否超过库存数量
				if (number > inventory) {
					number = inventory;
					uni.showToast({
						title: "库存数量" + inventory + inventory_unit
					})
				}
				this.buy_number = number

				// 存在规格的时候是否已完全选择规格
				var spec = this.goods_selected_spec();
				var sku_count = this.goods_spec_choose.length;
				var active_count = spec.length;
				if (sku_count > 0 && active_count < sku_count) {
					return false;
				}

				// 获取数据
				var data = this.params;
				data['id'] = this.goods_spec_base_id;

				data['goods_id'] = this.goods.id;
				data['spec'] = spec;
				data['stock'] = this.buy_number;

				let url = app.globalData.get_request_url("stock");
				uni.request({
					url: url,
					data: data,
					method: 'POST',
					success: (res) => {
						if (res.data.code == 200) {
							this.goods_spec_detail_back_handle(res.data.data);
						} else {
							if (app.globalData.is_login_check(res.data, this, 'get_data')) {
								uni.showToast({
									icon: 'none',
									title: res.data.msg,
									duration: 3000
								});
							}
						}
						uni.hideLoading()
					}
				})
			},
			// 详情图片查看
			goods_detail_images_view_event(e) {
				var value = e.currentTarget.dataset.value || null;
				if (value != null) {
					uni.previewImage({
						current: value,
						urls: [value]
					});
				}
			},
			// 提交订单
			buy_submit_event() {
				var temp_data = this.goods_spec_List;
				var sku_count = temp_data.length;
				var active_count = 0;
				var goods_data = [];
				
				this.goods_spec_List.forEach((item, key) => {
					if ((item.is_active || null) != null) {
						var spec = [];
						var sku = item.sku.split(',');
						var len = sku.length;
						sku.forEach((value, index) => {
							var name = '';
							if (len > 2) {
								if (index == 0) {
									name = '尺寸'
								} else if (index == 1) {
									name = '规格'
								} else {
									name = '金重'
								}
							} else {
								if (index == 0) {
									name = '规格'
								} else {
									name = '金重'
								}
							}
				
							spec.push({
								type: name,
								value: value
							});
						})
						goods_data.push({
							seckillId:this.goods.seckillId,
							productId: item.productId,
							attrvId: item.attrvId,
							cartNum: this.buy_number[key],
						});
					}
				});
				
				var seckillId = '';
				var productId = '';
				var attrvid = '';
				var cartNum = '';
				goods_data.forEach(item=>{
					seckillId = item.seckillId;
					productId = item.productId;
					attrvid = item.attrvId;
					cartNum = item.cartNum;
				})
				if(cartNum>this.goods.num){
					uni.showToast({
						title:"限购数量为" + this.goods.num,
						icon:'none'
					})
					return;
				}
				
				if (goods_data.length <= 0) {
					uni.showToast({
						title: "请选择重量和条码"
					})
					return false;
				}
				var data = {
					seckillId:seckillId,
					productId:productId,
					attrvid:attrvid,
					cartNum:cartNum,
				};
				uni.navigateTo({
					url:"/pages/seckill_order/seckill_order?data=" + JSON.stringify(data)
				})
			},
			// 关闭弹出层
			closePopup() {
				this.$emit("closePopup")
			},
			// 金料额
			GoldMaterial(Info) {
				const weight = parseFloat(Info.goldWeight);
				const price = parseFloat(Info.goldPrice);
				if (!isNaN(price) && !isNaN(weight)) {
					var totalGoldValue = (weight * price);
					return totalGoldValue.toFixed(2);
				} else {
					return '0.00'
				}
			},
			// 批发工费总额
			calculateTotalCost(info) {
				// 批发工费
				const wholesaleWage = parseFloat(info.wholesaleWage);
				// 金重
				const goldWeight = parseFloat(info.goldWeight);
				// 批发附加费
				const wholesaleSurcharge = parseFloat(info.wholesaleSurcharge);
				// 批发其他工费
				const wholesaleOtherExpenses = parseFloat(info.wholesaleOtherExpenses);

				if (!isNaN(wholesaleWage) && !isNaN(goldWeight) && !isNaN(wholesaleSurcharge) && !isNaN(
						wholesaleOtherExpenses)) {
					const totalCost = (wholesaleWage * goldWeight) + (wholesaleSurcharge * goldWeight) +
						wholesaleOtherExpenses;
					return totalCost.toFixed(2);
				} else {
					return '0.00';
				}
			},
			// 销售工费总额
			calculateTotal(xsInfo) {
				// 批发工费
				const wage = parseFloat(xsInfo.wage);
				// 金重
				const weight = parseFloat(xsInfo.goldWeight);
				// 销售附加费
				const surcharge = parseFloat(xsInfo.surcharge);
				// 销售其他工费
				const otherExpenses = parseFloat(xsInfo.otherExpenses);

				if (!isNaN(wage) && !isNaN(weight) && !isNaN(surcharge) && !isNaN(otherExpenses)) {
					const totalCost = (wage * weight) + (surcharge * weight) + otherExpenses;
					return totalCost.toFixed(2);
				} else {
					return '0.00';
				}
			},
			active(index, price) {
				if (index == 0) {
					this.$set(this.state, index, !this.state[index])
				} else {
					this.$set(this.state, index, !this.state[index])
				}
				if (this.state[index]) {
					this.price = parseFloat(parseFloat(this.price) + parseFloat(price)).toFixed(2)
				} else {
					this.price = parseFloat(parseFloat(this.price) - parseFloat(price)).toFixed(2)
				}
			},

			clickSize(index) {
				this.$set(this.stateSize, index, !this.stateSize[index])
			},
			jiannum(index) {
				if (this.goods_spec_List[index].is_active != null && this.goods_spec_List[index].is_active !== '') {
					if (this.buy_number[index] > 1) {
						this.$set(this.buy_number, index, this.buy_number[index] - 1)
					}
				} else {
					uni.showToast({
						title: "请选择重量和条码",
						icon: "none"
					})
				}

			},
			addnum(index) {
				var single_inventory;
				let exceededInventory = false;
				if (this.goods_spec_List[index].is_active != null && this.goods_spec_List[index].is_active !== '') {
					single_inventory = this.goods_spec_List[index].inventory;
					if (this.buy_number[index] + 1 > single_inventory) {
						exceededInventory = true;
					} else {
						this.$set(this.buy_number, index, this.buy_number[index] + 1);
						exceededInventory = false;
					}
				} else {
					uni.showToast({
						title: "请选择重量和条码",
						icon: "none"
					});
				}
				if (exceededInventory) {
					uni.showToast({
						title: "库存为" + single_inventory,
						icon: "none"
					});
				}
			},
			jiannum_dh() {
				if (this.dhnum > 0) {
					this.dhnum -= 1
				}
			},
			addnum_dh() {
				this.dhnum += 1
			},
			clickgg(index) {
				this.$set(this.ggState, index, !this.ggState[index])

			},
			clickjz(index) {
				this.$set(this.jzState, index, !this.jzState[index])
			},
			addshow() {
				this.ssAdd = !this.ssAdd
			},
			addGoods() {
				if (
					isNaN(parseFloat(this.goodsInfo.specify)) ||
					isNaN(parseFloat(this.goodsInfo.goldWeight)) ||
					isNaN(parseInt(this.goodsInfo.number))
				) {
					// 如果输入不都是数字，则弹出提示
					uni.showToast({
						title: '输入错误，请确保所有字段都是数字',
						icon: 'none'
					});

					return;
				}

				let goods = {}
				for (let k in this.goodsInfo) {
					goods[k] = this.goodsInfo[k]
				}
				this.goodsLists.push(goods)
				this.goodsInfo.specify = ""
				this.goodsInfo.goldWeight = ""
				this.goodsInfo.number = ""
				// 保存数据到本地存储
				uni.setStorageSync('saveList', this.goodsLists);
			},
			// 删除商品的方法
			removeGoods(index) {

				// 通过下标删除对应数组中的元素
				this.goodsLists.splice(index, 1)
			},
			// 限制只能输入数字
			limitToNumber(key, event) {

				// 获取输入的值
				let value = event.target.value;
				// 使用正则表达式替换非数字字符
				value = value.replace(/\D/g, '');
				// 更新数据模型
				this.goodsInfo[key] = value;
			},
			addCart(id) {
				uni.navigateTo({
					url:"/pages/seckill_order/seckill_order?id=" + id
				})
			}
		},
		mounted() {
			setTimeout(() => {
				for (let key in this.goods_spec_List) {
					this.buy_number.push(1)
				}
			}, 1000)

		},
		onLoad() {
			this.token = uni.getStorageSync("token")

			for (i in this.ggList) {
				this.ggState.push(false)
			}
			for (j in this.jzList) {
				this.jzState.push(false)
			}
			for (k in this.sizeList) {
				this.stateSize.push(false)
			}
			// 从本地存储中获取数据
			let saveList = uni.getStorageSync('saveList');

			var user = uni.getStorageSync("userinfo");
			this.vipCertification = user.vipCertification
		}
	};
</script>
<style>
	.right-conent {
		width: calc(100% - 200rpx);
	}

	.ht-auto {
		height: 100% !important;
	}

	.padding-main {
		padding: 20rpx;
	}

	.bs-bb {
		box-sizing: border-box;
	}

	.right-conent-only-level-one {
		width: 100%;
	}

	.right-conent-only-level-one .spec-images {
		width: 34rpx;
		height: 34rpx !important;
	}

	.oh {
		overflow: hidden;
	}

	.padding-vertical-main {
		padding-top: 20rpx;
		padding-bottom: 20rpx;
	}

	.fl {
		float: left;
	}

	.item-left {
		width: calc(100% - 290rpx);
	}

	.text-size-xs {
		font-size: 24rpx !important;
	}

	.dis-inline-block {
		display: inline-block !important;
	}

	.va-m {
		vertical-align: middle;
	}

	.radius {
		border-radius: 10rpx !important;
	}

	.margin-right {
		margin-right: 15rpx;
	}

	.spec-images {
		width: 50rpx;
		height: 50rpx !important;
	}

	.sales-price {
		color: #f40;
		font-weight: bold;
		font-size: 28rpx;
	}

	.tc {
		text-align: center;
	}

	.round {
		border-radius: 50rpx !important;
	}

	.fr {
		float: right;
	}

	.item-right {
		background: #fbfbfb;
		border: 1px solid #f0f0f0;
	}

	.margin-top-xs {
		margin-top: 5rpx;
	}

	.number-submit {
		width: 80rpx;
		font-weight: bold;
		padding: 0;
		height: 60rpx;
		line-height: 60rpx;
	}

	.cr-gray {
		color: #888 !important;
	}

	.bg-white {
		background-color: #fff !important;
	}

	.radius-0 {
		border-radius: 0 !important;
	}

	.pa-bott {
		margin-bottom: 80rpx;
	}

	.main {
		height: 500px;
		background-color: white;
		overflow: auto;
		font-size: 13px;
	}

	.content_type {
		width: 100%;
		height: 30px;
		text-align: center;
		line-height: 30px;
		display: flex;
		align-items: center;
		justify-content: space-around;
		border-bottom: 1rpx solid #f4f4f4;
	}

	/* 现货 */

	.xz {
		background-color: white;
		border: 1px solid #e93325;
	}

	.content_type_xh,
	.content_type_dh {
		width: 50%;
	}

	.active {
		color: red;
		border-bottom: 2px solid red;
	}

	.content_top {
		display: flex;
		height: 100px;
		padding-top: 10px;
		border-bottom: 1rpx solid #f4f4f4;
	}

	.content_top_images image {
		width: 100px;
		height: 100px;
	}

	.content_top_main {
		margin-left: 10px;
	}

	.content_top_main_one {
		width: 230px;
		height: 20px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.content_top_main_two,
	.content_top_main_three,
	.content_top_main_four {
		margin-top: 8px;
		color: black;
	}

	.content_top_main_three,
	.content_top_main_four {
		display: flex;
	}

	.content_top_main_inventory {
		margin-left: 10px;
	}

	.content_top_main_jcPrice {
		display: flex;
	}

	.content_top_main_surcharge {
		display: flex;
		margin-left: 10px;
	}

	.red {
		color: red;
		display: flex;
	}

	/* 提示 */
	.order_tip {
		height: 30px;
		text-align: center;
		line-height: 30px;
		display: flex;
		border-bottom: 1rpx solid #f4f4f4;
	}

	.tip {
		color: red;
		padding-left: 20rpx;
	}

	.tip_con {
		color: red;
	}

	/* 尺寸 */
	.size {
		width: 100%;
		position: relative;
		display: flex;
		border-bottom: 1rpx solid #f4f4f4;
	}

	.size_name {
		position: absolute;
		top: 0;
		left: 20rpx;
		letter-spacing: 10px;
		text-align: center;
		line-height: 30px;
		font-size: 14px;
		color: black;
	}

	.size_type {
		margin-left: 15%;
		width: 80%;
		display: flex;
		flex-wrap: wrap;
		align-items: center;
	}

	.size_type_one {
		width: 15%;
		height: 25px;
		text-align: center;
		line-height: 25px;
		background-color: #f1f7f7;
		border-radius: 5px;
		border: 1px solid #8a8585;
		margin: 5px 5px;
		padding-right: 10px;
	}

	/* .size_type_one:hover{
	color: white;
	background-color: red;
} */
	.activeSize {
		color: white;
		background-color: red;
		border: 0;
	}

	/* 数量 */
	.number {
		height: 40px;
		text-align: center;
		line-height: 40px;
		display: flex;
		border-bottom: 1rpx solid #f4f4f4;
	}

	.number_name {
		letter-spacing: 10px;
		padding-left: 20rpx;
		font-size: 14px;
		color: black;
	}

	.nub {
		position: relative;
		width: 100px;
		display: flex;
		align-items: center;
		justify-content: space-around;
	}

	.zero {
		width: 140px;
		height: 30px;
		text-align: center;
		line-height: 30px;
		border-radius: 20px;
		background-color: #f1f7f7;
		color: black;
	}

	.jian {
		position: absolute;
		top: 7px;
		left: 4px;
		width: 20px;
		height: 25px;
		border-radius: 50%;
		background-color: #ffffff;
		text-align: center;
		line-height: 25px;
		color: #c0c0c0;
	}

	.jia {
		position: absolute;
		top: 7px;
		right: 4px;
		width: 20px;
		height: 25px;
		border-radius: 50%;
		background-color: #ffffff;
		text-align: center;
		line-height: 25px;
		color: #c0c0c0;
	}

	/* 商品列表 */
	.content_bottom {
		margin-bottom: 70px;
		/* height: 300px; */
	}

	.jl_footer {
		padding-bottom: 50px;
	}

	.content_bottom_item {
		width: 90%;
		height: 70px;
		background-color: #f1f7f7;
		border-radius: 10px;
		margin: 10px auto;
		padding-left: 20rpx;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
		font-size: 10px;
		position: relative;
	}

	.content_bottom_item .xuanzong {
		width: 50rpx;
		height: 50rpx;
		position: absolute;
		bottom: 0;
		right: 0;
	}

	.content_bottom_item_two {
		display: flex;
		/* margin-lept: 10px; */
		margin-top: 8px;
	}

	.kc {
		margin-left: 10rpx;
	}

	.content_bottom_item_two_price {
		margin-left: 10px;
	}

	.content_bottom_item_three {
		margin-bottom: 2px;
		margin-top: -8px;
	}

	.content_bottom_item_four {
		display: flex;
		/* margin-left: 10px; */
		margin-top: -13px;
	}

	.content_bottom_item_four_price {
		margin-left: 10px;
	}

	/* 数量 */
	.many {
		height: 30px;
		line-height: 30px;
		background-color: #f1f7f7;
		position: absolute;
		bottom: 20%;
		right: 12%;
	}

	.many_item {
		width: 30px;
		height: 30px;
		line-height: 30px;
		text-align: center;
		padding: 15rpx 15rpx 15rpx 15rpx;
		border: 1px solid black;
	}

	.many_zero {
		border-left: none;
		border-right: none;
	}

	/* 订货 */
	.time {
		display: flex;
	}

	.dhlc {
		width: 100%;
		height: 40px;
		display: flex;
		align-items: center;
		justify-content: space-around;
		border-bottom: 1rpx solid #f4f4f4;
	}

	.dhlc_ico {
		display: flex;
		align-items: center;
		color: red;
		font-size: 12px;
		letter-spacing: 2px;
	}

	.dhlc_name {
		color: black;
	}

	.dhlc_ico image {
		width: 25px;
		height: 25px;
	}

	.dhlc_why image {
		width: 25px;
		height: 25px;
	}

	/* 提醒 */
	.tx {
		width: 100%;
		height: 25px;
		border-bottom: 1rpx solid #f4f4f4;
		text-align: center;
		line-height: 25px;
		margin-left: 15px;
	}

	/* 注释 */
	.note {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		/* border-bottom: 1rpx solid #f4f4f4; */
		margin-left: 5px;
	}

	.note_logo image {
		width: 25px;
		height: 25px;
	}

	.note_title {
		margin-left: 10px;
		margin-right: 10px;
		margin-top: 10px;
	}

	.hong {
		display: inline-block;
		color: red;
	}

	/* 多选列表 */
	.list {
		margin-top: 10px;
		padding-bottom: 60px;
	}

	.list_item {
		margin-top: 10px;
		margin-left: 15px;
		font-size: 12px;
		padding-bottom: 10px;
	}

	.list_item button {
		margin: auto;
		width: 120px;
		font-size: 17px;
		background-color: #e2d2ae;
	}

	.list_item input {
		border: 1px solid black;
		width: 103px;
		margin-top: 10px;
		margin-bottom: 7px;
	}

	.addgoods {
		width: 100%;
		text-align: center;
		margin-top: 10px;
	}

	.table {
		display: flex;
		flex-direction: column;
		border: 1px solid #000;
		margin-left: 15px;
		margin-right: 15px;
	}

	.row {
		display: flex;
		border-bottom: 1px solid #000;
	}

	.header {
		font-weight: bold;
	}

	.cell {
		flex: 1;
		padding: 5px;
		text-align: center;
		border-right: 1px solid black;
		font-size: 15px;
	}

	/* 规格 */
	/* 金重 */
	.gold_weight {
		border-top: 1rpx solid #f4f4f4;
	}

	.specifications,
	.gold_weight {
		width: 100%;
		position: relative;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 10px;
	}

	.specifications_name,
	.gold_weight_name {
		position: absolute;
		top: 10px;
		left: 10px;
		color: black;
		font-size: 14px;
		letter-spacing: 2px;
	}

	.specifications_type,
	.gold_weight_type {
		/* position: absolute; */
		margin-left: 15%;
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		align-items: center;
	}

	.specifications_type_one,
	.gold_weight_type_one {
		width: 15%;
		height: 25px;
		text-align: center;
		line-height: 25px;
		background-color: #f1f7f7;
		border-radius: 5px;
		margin: 5px 5px;
		padding-right: 10px;
		border: 1px solid #8a8585;
	}

	/* 数量 */
	.number_dh {
		border-top: 1rpx solid #f4f4f4;
	}

	/* 注意 */
	.attention {
		/* border-top: 1rpx solid #f4f4f4; */
		width: 100%;
		margin: 15px 15px;
		font-size: 13px;
		margin-bottom: 20px;
	}

	.attention_name {
		padding-right: 30px;
	}

	/* 加入购物车 */
	.content_addCart {
		position: fixed;
		bottom: 0;
		left: 50%;
		transform: translateX(-50%);
		width: 100%;
		padding-bottom: 10px;
		background-color: white;
		padding-top: 10px;
		/* height: 50px; */
	}

	.total {
		margin-bottom: 10px;
		margin-left: 20px;
		font-weight: bold;
	}

	.addCart {
		width: 90%;
		height: 40px;
		margin: 0 auto;
		border-radius: 20px;
		text-align: center;
		line-height: 40px;
		/* background-color: #edb8b4; */
		background-color: #e93325;
		font-size: 15px;
		color: white;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.num {
		margin-left: 5px;
	}
</style>